package com.cyf.Coupon;

import com.cyf.Coupon.service.CouponService;
import com.cyf.merchat.network.bean.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 优惠券信息
 */
@RestController
@RequestMapping(value = "coupon")
@Api(value = "车主优惠券信息")
public class CouponHttpController {

    @Autowired
    private CouponService couponService;

    /**
     * 支付时车主获取可用优惠券
     *
     * @param req
     * @return
     */
    @ApiOperation(value = "车主查询可用优惠券")
    @PostMapping(value = "/userIssueRecord")
    public MerchantCouponLssueRecordRsp userIssueRecord(@RequestBody UserIssueRecordReq req) {
        return couponService.userIssueRecord(req);
    }

    /**
     * 支付时车主获取可用优惠券
     *
     * @param orderNo
     * @return
     */
    @ApiOperation(value = "车主查询可用优惠券（富茂）")
    @PostMapping(value = "/userIssueRecordFuMao")
    public MerchantCouponLssueRecordRsp userIssueRecordFuMao(@RequestParam String orderNo) {
        return couponService.userIssueRecordFuMao(orderNo);
    }

    /**
     * 车主获取自己的优惠券列表（E停宝）
     * 查询全部status =-1
     * 已使用的status = 0
     *
     * @param openId
     * @return
     */
    @ApiOperation(value = "车主查询我的全部车场优惠券")
    @PostMapping(value = "/userCoupon")
    public MerchantCouponLssueRecordRsp userCoupon(@RequestParam String openId, @RequestParam int status,@RequestParam(required = false) String phone ) {
        return couponService.userCoupon(openId, status,phone);
    }

    /**
     * 车主选择抵扣的优惠券,修改优惠券信息
     *
     * @return
     */
    @ApiOperation(value = "车主选择抵扣的优惠券")
    @PostMapping(value = "/couponUse")
    public MerchantBusinessRsp couponUse(@RequestBody CouponUseReq couponUseReq) {
        return couponService.couponUse(couponUseReq.getCouponId(), couponUseReq.getOrderNo());
    }


    @ApiOperation(value = "车主支付成功页展示信息")
    @PostMapping(value = "/paySuccessInfo")
    public PaySuccessRsp paySuccessInfo(@RequestParam String orderNo) {
        return couponService.paySuccessInfo(orderNo);
    }


    @ApiOperation(value = "支付失败退电子优惠券接口")
    @PostMapping(value = "/returnInvoice")
    public ReturnInvoiceRsp returnInvoice(@RequestParam String qrcodeIds) {
        return couponService.returnInvoice(qrcodeIds);
    }
}
